;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: namespaces.lisp,v 1.9 2005/10/06 11:06:56 scaekenberghe Exp $
;;;;
;;;; Definition of some standard XML namespaces commonly needed for SOAP
;;;;
;;;; Copyright (C) 2005 Sven Van Caekenberghe, Beta Nine BVBA. All Rights Reserved.
;;;;
;;;; You are granted the rights to distribute and use this software
;;;; as governed by the terms of the Lisp Lesser GNU Public License
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
;;;;

(in-package :cl-soap)

;;; SOAP Envelope

(defconstant +soapenv-ns-uri+ "http://schemas.xmlsoap.org/soap/envelope/")

(defpackage :soapenv
  (:nicknames "soapenv")
  (:export "Envelope" "Header" "Body" "Fault" "encodingStyle")
  (:documentation "Package for symbols in the SOAP Envelope XML Namespace"))

#|
(defparameter *soapenv-ns* (s-xml:register-namespace +soapenv-ns-uri+ "soapenv" :soapenv))
|#

;;; XSD
;; these wave been observed in the wild so far:
(defconstant +xsd1999-ns-uri+ "http://www.w3.org/1999/XMLSchema")
(defconstant +xsd2000-ns-uri+ "http://www.w3.org/2000/10/XMLSchema")
(defconstant +xsd2001-ns-uri+ "http://www.w3.org/2001/XMLSchema")

;; For simplicity we currently to not distinguish them: We have one
;; package :XSD that is registered for all 3 well-known URIs

(defpackage :xsd
  (:nicknames "xsd")
  (:export "schema" "element" "simpleType" "complexType" "complexContent" 
           "sequence" "choice" "all" "attribute"
           "restriction" "extension" "maxLength" "pattern" "list" "union" "enumeration"
	   "include" "import" "any")
  (:documentation "Package for symbols in the XML Schema Definition XML Namespace"))

#|
(defparameter *xsd1999-ns*
  (s-xml:register-namespace +xsd1999-ns-uri+ "xsd" :xsd))

(defparameter *xsd2000-ns*
  (s-xml:register-namespace +xsd2000-ns-uri+ "xsd" :xsd))

(defparameter *xsd2001-ns*
  (s-xml:register-namespace +xsd2001-ns-uri+ "xsd" :xsd))
|#

;;; XSI

(defconstant +xsi1999-ns-uri+ "http://www.w3.org/1999/XMLSchema-instance")
(defconstant +xsi2000-ns-uri+ "http://www.w3.org/2000/10/XMLSchema-instance")
(defconstant +xsi2001-ns-uri+ "http://www.w3.org/2001/XMLSchema-instance") 


(defpackage :xsi
  (:nicknames "xsi")
  (:export "null" "type")
  (:documentation "Package for symbols in the XML Schema Instance XML Namespace"))

#|
(defparameter *xsi1999-ns* (s-xml:register-namespace +xsi1999-ns-uri+ "xsi" :xsi))
(defparameter *xsi2000-ns* (s-xml:register-namespace +xsi2000-ns-uri+ "xsi" :xsi))
(defparameter *xsi2001-ns* (s-xml:register-namespace +xsi2001-ns-uri+ "xsi" :xsi))
|#

;;; SOAP Encoding

(defconstant +soap-enc-ns-uri+ "http://schemas.xmlsoap.org/soap/encoding/")

;;; WSDL

(defconstant +wsdl1.1-ns-uri+ "http://schemas.xmlsoap.org/wsdl/")
(defconstant +wsdl1.2-ns-uri+ "http://www.w3.org/2003/06/wsdl")

(defpackage :wsdl
  (:nicknames "wsdl")
  (:export 
   "definitions" "documentation"
   "portType" "message" "operation" "port" "service" "binding" "part" "input" "output" "fault" "types")
  (:documentation "Package for symbols in the WSDL XML Namespace"))

#|
(defparameter *wsdl1.1-ns* (s-xml:register-namespace +wsdl1.1-ns-uri+ "wsdl" :wsdl))
(defparameter *wsdl1.2-ns* (s-xml:register-namespace +wsdl1.2-ns-uri+ "wsdl" :wsdl))
|#

;;; WSDL Soap Binding

(defconstant +wsdl-soap1.1-ns-uri+ "http://schemas.xmlsoap.org/wsdl/soap/")
(defconstant +wsdl-soap1.2-ns-uri+ "http://www.w3.org/2003/06/wsdl/soap12")

(defpackage :wsdl-soap
  (:nicknames "wsdl-soap")
  (:export "address" "binding" "operation" "body" "header" "fault" "headerfault")
  (:documentation "Package for symbols in the WSDL Soap Bindings XML Namespace"))

#|
(defparameter *wsdl-soap1.1-ns* (s-xml:register-namespace +wsdl-soap1.1-ns-uri+ "soap" :wsdl-soap))
(defparameter *wsdl-soap1.2-ns* (s-xml:register-namespace +wsdl-soap1.2-ns-uri+ "soap" :wsdl-soap))
|#


;;; initialization to defaults
(defun initialize-soap-environment ()
  "Define the namespaces, types and elements that CL-SOAP relies on."
  ;; set namespaces
  
  (s-xml:register-namespace +xsd2001-ns-uri+ "xsd" :xsd)
  (s-xml:register-namespace +xsd1999-ns-uri+ "xsd" :xsd)
  (s-xml:register-namespace +xsd2000-ns-uri+ "xsd" :xsd)
  (s-xml:register-namespace +xsi1999-ns-uri+ "xsi" :xsi)
  (s-xml:register-namespace +xsi2000-ns-uri+ "xsi" :xsi)
  (s-xml:register-namespace +xsi2001-ns-uri+ "xsi" :xsi)
  (s-xml:register-namespace +wsdl1.1-ns-uri+ "wsdl" :wsdl)
  (s-xml:register-namespace +wsdl1.2-ns-uri+ "wsdl" :wsdl)
  
  ;; WSDL SOAP binding 
  (s-xml:register-namespace +wsdl-soap1.1-ns-uri+ "soap" :wsdl-soap)
  (s-xml:register-namespace +wsdl-soap1.2-ns-uri+ "soap" :wsdl-soap)
  ;; SOAP message encoding
  (s-xml:register-namespace +soapenv-ns-uri+ "soapenv" :soapenv)
  ;;; namespace maps:
  ;; Default keyword designated maps
  
  (s-xml:register-namespace-map :schema1999 `(nil (,(s-xml:find-namespace +xsd1999-ns-uri+))))
  (s-xml:register-namespace-map :schema2000 `(nil (,(s-xml:find-namespace +xsd2000-ns-uri+))))
  (s-xml:register-namespace-map :schema2001 `(nil (,(s-xml:find-namespace +xsd2001-ns-uri+))))
  (s-xml:register-namespace-map :schema   `(nil :schema2001 :schema1999 :schema2000))
  (s-xml:register-namespace-map :schema1  `(nil :schema1999 :schema2001 :schema2000))
  
  (s-xml:register-namespace-map :soap1.1 `(nil (,(s-xml:find-namespace +wsdl-soap1.1-ns-uri+))))
  (s-xml:register-namespace-map :soap1.2 `(nil (,(s-xml:find-namespace +wsdl-soap1.2-ns-uri+))))
  (s-xml:register-namespace-map :soap    '(nil :soap1.2 :soap1.1 :schema))
  (s-xml:register-namespace-map :soap1   '(nil :soap1.1 :soap1.2 :schema))
  
  (s-xml:register-namespace-map :wsdl1.1 `(nil (,(s-xml:find-namespace +wsdl1.1-ns-uri+))))
  (s-xml:register-namespace-map :wsdl1.2 `(nil (,(s-xml:find-namespace +wsdl1.2-ns-uri+))))
  (s-xml:register-namespace-map :wsdl-namespaces   '(nil :wsdl1.2 :wsdl1.1 :soap))
  (s-xml:register-namespace-map :wsdl1-namespaces  '(nil :wsdl1.1 :wsdl1.2 :soap))
  (s-xml:register-namespace-map :wsdl-combine   '(nil :wsdl-namespaces :all (:wsdl-data nil :any)))
  (s-xml:register-namespace-map :wsdl1-combine  '(nil :wsdl1-namespaces :all (:wsdl-data nil :any)))
  (s-xml:register-namespace-map :wsdl-keyword   '(nil :wsdl-namespaces :all (:keyword nil :any)))
  (s-xml:register-namespace-map :wsdl1-keyword  '(nil :wsdl1-namespaces :all (:keyword nil :any)))
  (s-xml:register-namespace-map :wsdl-prefix    '(nil :wsdl-namespaces :all ("wsdl-" nil :prefix)))
  (s-xml:register-namespace-map :wsdl1-prefix   '(nil :wsdl-namespaces :all ("wsdl-" nil :prefix)))
  ;;
  (values))

;;;; eof
